<template>
    <div class="page-account">
        <div v-if="showI18n" class="page-account-header">
            <i-header-i18n />
        </div>
        <div class="page-account-container">
            <div class="page-account-top">
                <!-- <div class="page-account-top-logo">
                    <img src="@/assets/images/logo.png" alt="logo">
                </div> -->
                <!-- <div class="page-account-top-desc">西乡街道人事管理系统</div> -->
                <div class="title">西乡街道人事管理系统</div>
            </div>
            <Login @on-submit="handleSubmit">
                <UserName name="username" v-model="username" />
                <Password name="password" v-model="password" enter-to-submit />
                <div class="page-account-auto-login">
                    <Checkbox v-model="autoLogin" size="large">{{ $t('page.login.remember') }}</Checkbox>
                    <!-- <a href="">{{ $t('page.login.forgot') }}</a> -->
                </div>
                <Submit :loading="submiting">{{ $t('page.login.submit') }}</Submit>
                <!-- <button @click="handleClick">登录</button> -->
            </Login>
            <div class="state">管理员测试账号：admin</div>
            <div class="state">密码：123456</div>
            <!-- <div class="state">测试账号：18681555555</div>
            <div class="state">密码：admin654321.</div> -->
            <!-- 其他登录方式 微信 QQ 新浪微博 -->
            <!-- <div class="page-account-other">
                <span>{{ $t('page.login.other') }}</span>
                <img src="@/assets/svg/icon-social-wechat.svg" alt="wechat">
                <img src="@/assets/svg/icon-social-qq.svg" alt="qq">
                <img src="@/assets/svg/icon-social-weibo.svg" alt="weibo">
                <router-link class="page-account-register" :to="{ name: 'register' }">{{ $t('page.login.signup') }}</router-link>
            </div> -->
        </div>
        <i-copyright />
    </div>
</template>
<script>
    import { frameInRoutes } from '@/router/routes';
    import BasicLayout from '@/layouts/basic-layout';
    import iCopyright from '@/components/copyright';
    import { mapActions } from 'vuex';
    import mixins from '../mixins';

    export default {
        mixins: [ mixins ],
        components: { iCopyright },
        data () {
            return {
                username: '',
                password: '',
                autoLogin: false,
                submiting: false,
            }
        },
        mounted() {
        },
        methods: {
            handleClick() {
                let params = {
                    account: "123",
                    password: "123"
                }
                this.$axios.post("http://kwapi.dev.zhiyuketang.cn/admin/login", params).then(res => {
                    console.log(res)
                });
            },
            ...mapActions('admin/account', [
                'login'
            ]),
            /**
             * @description 登录
             * 表单校验已有 iView Pro 自动完成，如有需要修改，请阅读 iView Pro 文档
             */
            handleSubmit (valid, values) {
                if (valid) {
                    this.submiting = true;
                    const { username, password } = values;
                    this.login({
                        username,
                        password,
                        'autoLogin': this.autoLogin
                    }).then(res => {
                        let userinfo = res.data.data.userinfo
                        // debugger
                        // 权限判定，动态添加路由
                        /* if(userinfo.access.some(item=>item==="admin")) {
                            console.log("res", userinfo)
                            let addRoutes = [
                                {
                                    path: '/',
                                    redirect: {
                                        name: 'index'
                                    },
                                    component: BasicLayout,
                                    children: [
                                        {
                                            path: 'index',
                                            name: 'index',
                                            meta: {
                                                title: '人事管理系统',
                                                auth: true,
                                                closable: false
                                            },
                                            component: () => import('@/pages/index')
                                        },
                                        {
                                            path: 'tabs/examinee',
                                            name: 'examinee',
                                            meta: {
                                                title: '管理员管理',
                                                auth: ['admin'],
                                                closable: false
                                            },
                                            component: () => import('@/pages/tabs/examinee/index')
                                        },
                                        
                                        {
                                            path: 'tabs/examiner',
                                            name: 'examiner',
                                            meta: {
                                                title: '考务人员管理',
                                                auth: ['admin'],
                                                closable: false
                                            },
                                            component: () => import('@/pages/tabs/examiner/index')
                                        },{
                                            path: 'tabs/examinationProject',
                                            name: 'examinationProject',
                                            meta: {
                                                title: '考务项目管理',
                                                auth: ['admin'],
                                                closable: false
                                            },
                                            component: () => import('@/pages/tabs/examinationProject/index')
                                        },
                                        // 刷新页面 必须保留
                                        {
                                            path: 'refresh',
                                            name: 'refresh',
                                            hidden: true,
                                            component: {
                                                beforeRouteEnter (to, from, next) {
                                                    next(instance => instance.$router.replace(from.fullPath));
                                                },
                                                render: h => h()
                                            }
                                        },
                                        // 页面重定向 必须保留
                                        {
                                            path: 'redirect/:route*',
                                            name: 'redirect',
                                            hidden: true,
                                            component: {
                                                beforeRouteEnter (to, from, next) {
                                                    next(instance => instance.$router.replace(JSON.parse(from.params.route)));
                                                },
                                                render: h => h()
                                            }
                                        }
                                    ]
                                }
                            ]
                            // 动态加载路由，routes 为数组
                            this.$router.addRoutes(addRoutes);
                            const newRoutes = frameInRoutes.concat(addRoutes);
                            // 完整的 frameInRoutes，更新 vuex 的数据
                            this.$store.commit('admin/page/init', newRoutes);
                        } */
                        this.submiting = false;
                        // 重定向对象不存在则返回顶层路径
                        this.$router.replace(this.$route.query.redirect || '/');
                    }).catch(err => {
                        this.submiting = false;
                    })
                }
            }
        }
    };
</script>

<style scoped>
    .title {
        font-size: 30px;
        font-weight: bold;
        color: #808695;
        padding-top: 150px;
    }
</style>